<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>井库选择</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>

<body>
    <form class="layui-form" action="">

        <div class="layui-form" lay-filter="">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>井库选择</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">井库名：</label>
                <div class="layui-input-inline" style="width:160px">
                    <select id="dbname" class="from-control" lay-filter="dbname" class="layui-select"
                        lay-search></select>
                </div>
            </div>
        </div>

    </form>
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script type="text/javascript" src="../jquery-3.0.0.min.js"></script>
    <script type="text/javascript" src="../layui/public.js"></script>
    <script type='text/javascript'>
        var $;
        var form;
        var dataslist;
        layui.use(['form'], function () {
            $ = layui.$;
            form = layui.form;
            if (getoken != false) {
                var authorization = getoken;
                $.ajax({
                    type: "get",
                    url: api_address + '/gd/getdbname',
                    async: false,
                    headers: {
                        Authorization: authorization
                    },
                    contentType: 'application/json;',
                    success: function (res) {
                        if (res.code == 200) {
                            $("#dbname").append("<option value=''>请选择</option>");
                            for (var i = 0; i < res.data.length; i++) {
                                var option = "<option value=\"" + res.data[i] + "\"";
                                option += ">" + res.data[i] + "</option>"; //动态添加数据
                                $("#dbname").append(option);
                            }
                            layui.form.render();
                        }
                    }
                });
            }

        });

        function DBname(name) {
            $('#dbname').val(name);
            form.render();
        }

        //获取下拉框选中的值
        var retname = function () {
            var dbnames = $('#dbname').val();
            return dbnames;
        }
    </script>

</body>

</html>